package cn.xxxy.fourm.Controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.xxxy.fourm.entity.User;
import cn.xxxy.fourm.model.Node;
import cn.xxxy.fourm.service.MenuService;
import cn.xxxy.fourm.service.UserService;

@Controller
public class BackgroundController {
	@Autowired
	private MenuService menuService;
	@Autowired
	private UserService userService;
	
	@RequestMapping("/toHome")
	public String toHome(Model m,HttpSession s) {
		List<Node> lists=menuService.lists(0);		
		m.addAttribute("menus", lists);
		User user=(User) s.getAttribute("loginUser");
		
		m.addAttribute("loginUser", user);
		return "/background/home";
	}
	@PostMapping("/editPass")
	@ResponseBody
	public User toEditPass(String password,HttpSession s) {
		User user=(User) s.getAttribute("loginUser");
		user.setUpass(password);
		userService.addUser(user);
		return user;		
	}
}
